<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8" />
    <title>登录</title>
    <link rel="stylesheet" type="text/css" href="css/public.css" />
    <link rel="stylesheet" type="text/css" href="css/login.css" />
</head>

<body>
    <!-------------------login-------------------------->
    <div class="login">
        <form action="#" method="post">
            <h1><a href="index.html"></a></h1>
            <p></p>
            <div class="msg-warn hide">
                <b></b>公共场所不建议自动登录，以防账号丢失
            </div>
            <p>
                <input type="text" name="" id="user" value="" placeholder="手机号" />
            </p>
            <p>
                <input type="text" name="" id="password" value="" placeholder="密码" />
            </p>
            <p><input type="submit" name="" id="btn" value="登  录" /></p>
            <p class="txt">
                <a class="" href="reg.html">免费注册</a>
                <!-- <a href="forget.html">忘记密码？</a> -->
            </p>
        </form>
    </div>
</body>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/1.9.1/jquery.js"></script>
<script>
    var baseUrl = "http://127.0.0.1:8081";
    $("#btn").on("click", function () {
        var data = {
            tel: $("#user").val(),
            password: $("#password").val()
        };
        $.post(`${baseUrl}/login`, JSON.stringify(data), function (data) {
            if (data.result == 1) {
                localStorage.id = data.user.id
                window.location.href = "/sxw/mygrxx.html";
            } else {
                alert("用户或密码错误！");
                return;
            }
        }, "json");
    });
</script>

</html>